
package com.yulebaby.callsenter.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yulebaby.callsenter.R;
import com.yulebaby.callsenter.bean.CustomerBean;
import com.yulebaby.callsenter.global.App;
import com.yulebaby.callsenter.global.Constant;
import com.yulebaby.callsenter.utils.DateUtil;
import com.yulebaby.callsenter.utils.ImageLoader;

import java.util.List;


/**
 * Author: Zhangbo
 * Time: 2016/11/13
 * 初始Adapter 后修改 由于搜索时用到 未删 未修改
 * <p>
 */

public class CustomerInSeaAdapter extends BaseQuickAdapter<CustomerBean, BaseViewHolder> {

    public CustomerInSeaAdapter(List<CustomerBean> list) {
        super(R.layout.item_recycle_internationalwater, list);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, CustomerBean customerBean) {
        baseViewHolder.setText(R.id.tv_phonename, checkNull(customerBean.getCustomer_name()))
                .setText(R.id.tv_address, checkNull(customerBean.getAddress()))
                .setText(R.id.tv_nextvist, "上次跟踪时间： " + checkNull(DateUtil.formatDateTime(customerBean.getLast_contact_time())))
                .setText(R.id.tv_customerfrom, "信息来源： " + checkNull(customerBean.getFrom()))
                .addOnClickListener(R.id.iv_robcustomer)
                .addOnClickListener(R.id.tv_looktrack);
        ImageView throwView = baseViewHolder.getView(R.id.iv_robcustomer);
        switch (customerBean.getStressIntent()) {
            case Constant.StressIntent.STATE_NEWINROOM:
                ImageLoader.load(App.mContext, R.drawable.state_new, (ImageView) baseViewHolder.getView(R.id.iv_callstate));
                break;
            case Constant.StressIntent.STATE_STRONG:
                ImageLoader.load(App.mContext, R.drawable.state_strong, (ImageView) baseViewHolder.getView(R.id.iv_callstate));
                break;
            case Constant.StressIntent.STATE_MIDDLE:
                ImageLoader.load(App.mContext, R.drawable.state_middle, (ImageView) baseViewHolder.getView(R.id.iv_callstate));
                break;
            case Constant.StressIntent.STATE_COMMONLY:
                ImageLoader.load(App.mContext, R.drawable.state_commonly, (ImageView) baseViewHolder.getView(R.id.iv_callstate));
                break;
            case Constant.StressIntent.STATE_LOW:
            case Constant.StressIntent.STATE_NONE:
                ImageLoader.load(App.mContext, R.drawable.state_low, (ImageView) baseViewHolder.getView(R.id.iv_callstate));
                break;
        }
        switch (customerBean.getIsRobInSea()) {
            case 0:
                throwView.setClickable(true);
                throwView.setEnabled(true);
                throwView.setImageResource(R.drawable.rob_customer);
                break;
            case 1:
                throwView.setClickable(false);
                throwView.setEnabled(false);
                throwView.setImageResource(R.drawable.rob_customer_fail);
                break;
        }
    }

    /**
     * 判断是否为空
     *
     * @param string
     * @return
     */
    public String checkNull(String string) {
        if (TextUtils.isEmpty(string)) {
            return "";
        }
        return string;
    }

}

